package com.edu.exam.entity.examination.paper.technical;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import jakarta.persistence.*;
import java.time.LocalDateTime;

// 导入外部枚举类
import com.edu.exam.enums.examination.paper.AnswerRecognitionStatus;
import com.edu.exam.enums.examination.paper.AnswerReviewStatus;

/**
 * 答案识别结果实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：answer_recognition_result
 *
 * <p>根据E-04-03 OMR识别子模块数据库设计实现，
 * 存储客观题答案识别的详细信息，包括选择的选项、填涂强度、置信度、坐标信息等。
 * 用于OMR答题卡识别结果的存储和管理。</p>
 *
 * @author System
 * @version 1.0.0
 */

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class AnswerRecognitionResult {

    /**
     * 答案识别ID，主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "answer_id")
    private Long answerId;

    /**
     * 关联信息
     */
    @Column(name = "result_id", nullable = false)
    private Long resultId;

    @Column(name = "question_number", length = 50, nullable = false)
    private String questionNumber;

    @Column(name = "question_id")
    private Long questionId;

    /**
     * 答案识别结果
     */
    @Column(name = "selected_option", length = 10)
    private String selectedOption;

    @Column(name = "fill_intensity", precision = 5, scale = 2)
    private Double fillIntensity;

    @Column(name = "confidence_score", precision = 5, scale = 2)
    private Double confidenceScore;

    @Column(name = "is_multi_answer")
    private Boolean isMultiAnswer;

    /**
     * 位置信息（JSON格式）
     */
    @Column(name = "option_coordinates", columnDefinition = "JSON")
    private String optionCoordinates;

    @Column(name = "fill_region", columnDefinition = "JSON")
    private String fillRegion;

    @Column(name = "relative_position", columnDefinition = "JSON")
    private String relativePosition;

    @Column(name = "bubble_size", columnDefinition = "JSON")
    private String bubbleSize;

    /**
     * 质量指标
     */
    @Column(name = "clarity_score", precision = 5, scale = 2)
    private Double clarityScore;

    @Column(name = "completeness_score", precision = 5, scale = 2)
    private Double completenessScore;

    @Column(name = "fill_uniformity_score", precision = 5, scale = 2)
    private Double fillUniformityScore;

    @Column(name = "overall_quality_score", precision = 5, scale = 2)
    private Double overallQualityScore;

    /**
     * 异常检测
     */
    @Column(name = "has_erasure_marks")
    private Boolean hasErasureMarks;

    @Column(name = "has_multiple_selections")
    private Boolean hasMultipleSelections;

    @Column(name = "has_light_fill")
    private Boolean hasLightFill;

    @Column(name = "has_ambiguous_selection")
    private Boolean hasAmbiguousSelection;

    /**
     * 异常详情
     */
    @Column(name = "anomaly_details", columnDefinition = "JSON")
    private String anomalyDetails;

    @Column(name = "requires_manual_review")
    private Boolean requiresManualReview;

    /**
     * 处理信息
     */
    @Column(name = "recognition_algorithm", length = 100)
    private String recognitionAlgorithm;

    @Column(name = "processing_time_ms")
    private Integer processingTimeMs;

    @Column(name = "quality_threshold_applied", precision = 5, scale = 2)
    private Double qualityThresholdApplied;

    /**
     * 状态信息
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "recognition_status", length = 20, nullable = false)
    private AnswerRecognitionStatus recognitionStatus;

    @Enumerated(EnumType.STRING)
    @Column(name = "review_status", length = 20)
    private AnswerReviewStatus reviewStatus;

    /**
     * 时间信息
     */
    @Column(name = "created_time", nullable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 人工审核信息
     */
    @Column(name = "manual_review_by")
    private Long manualReviewBy;

    @Column(name = "manual_review_time")
    private LocalDateTime manualReviewTime;

    @Column(name = "manual_corrected_option", length = 10)
    private String manualCorrectedOption;

    @Column(name = "manual_review_notes", columnDefinition = "TEXT")
    private String manualReviewNotes;

    // 业务方法

    /**
     * 获取识别状态描述
     */
    public String getRecognitionStatusDescription() {
        return recognitionStatus != null ? recognitionStatus.getDescription() : null;
    }

    /**
     * 获取审核状态描述
     */
    public String getReviewStatusDescription() {
        return reviewStatus != null ? reviewStatus.getDescription() : null;
    }

    /**
     * 检查是否为成功识别状态
     */
}
